package com.vne.skyemart.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;

import com.vne.skyemart.model.CategoriesStore;
import com.vne.skyemart.service.CategoriesStoreService;

@Controller
@SessionAttributes
@RequestMapping("/categoriesStore")
public class CategoriesStoreController {

	@Autowired
	private CategoriesStoreService categoriesStoreService;

	@RequestMapping(value = "/save", method = RequestMethod.POST)
	public ModelAndView saveCategoriesStore(@ModelAttribute(" categoriesStore") CategoriesStore categoriesStore,
			BindingResult result) {
		 categoriesStoreService.addCategoriesStore(categoriesStore);
		return new ModelAndView("redirect:/categoriesStore.html");
	}

	@RequestMapping(method = RequestMethod.GET)
	public String listCategoriesStore(Model model) {
		model.addAttribute("categoriesStore",  categoriesStoreService.listCategoriesStore());

		return "categoriesStoreList";
	}

	@RequestMapping(value = "/add", method = RequestMethod.GET)
	public ModelAndView addCategoriesStore(@ModelAttribute("CategoriesStore") CategoriesStore categoriesStore,
			BindingResult result) {
		return new ModelAndView("addCategoriesStore");
	}
}
